package com.dq.demo.app;

import android.app.Activity;
import android.app.Application;
import android.content.Context;
import android.support.multidex.MultiDex;

import com.dq.demo.model.http.OkgoUtil;
import com.dq.demo.ui.activity.SplashActivity;
import com.dq.demo.util.AppFrontBackHelper;
import com.dq.demo.util.HomeReceiver;
import com.dq.demo.util.ILog;
import com.dq.demo.util.SharedPreferencesUtil;
import com.qmuiteam.qmui.arch.QMUISwipeBackActivityManager;
import org.litepal.LitePal;

/**
 * CreateName : Z-JC
 * Date : 2019/10/23
 * Describe :
 */
public class App extends Application {

    public static Context context;

    @Override
    protected void attachBaseContext(Context base) {
        super.attachBaseContext(base);
        MultiDex.install(base);
    }

    @Override
    public void onCreate() {
        super.onCreate();
        LitePal.initialize(this);//初始化litepal数据库
        context = getApplicationContext();
        SharedPreferencesUtil.getInstance(context);
        OkgoUtil.getInstance().init(this);
        QMUISwipeBackActivityManager.init(this);
        /** 配置广告SDK **/
        //UMConfigure.init(this, getString(R.string.UMENG_KEY), getString(R.string.UMENG_CHANNEL), UMConfigure.DEVICE_TYPE_PHONE, null);
        //UMConfigure.setProcessEvent(true);

        AppFrontBackHelper.getInstance().register(this, new AppFrontBackHelper.OnAppStatusListener() {
            @Override
            public void onFront(Activity activity) {
                //应用切到前台处理
                if (!(activity instanceof SplashActivity)) {
                    ILog.e("------------------------返回到程序前台:" + HomeReceiver.isBackground);
                    if (HomeReceiver.isBackground) {
                        HomeReceiver.isBackground = false;
                    }
                }
            }

            @Override
            public void onBack() {
                ILog.e("----------------------返回到程序后台...");
                if (HomeReceiver.isHome(getApplicationContext())) {
                    HomeReceiver.isBackground = true;
                }
            }
        });
    }
}